const App = getApp();
import util from '../../../utils/util.js'
import api from '../../../config/api.js'

const formatTime = util.formatTime;

Page({
  data: {
    trips: [],
    user_info: null,
  },
  onLoad(options) {
    const self = this;
    const userId = options.id || self.data.userId;
    util.request(api.userInfoByID + userId + '/v2/').then(function (res) {
      const trips = res.trips;
      trips.map((trip) => {
        const item = trip;
        item.date_added = formatTime(new Date(item.date_added * 1000), 1);
        return item;
      });
      self.setData({
        trips,
        userId: res.userId ? res.userId: '',
        user_info: res.user_info,
      });
      wx.setNavigationBarTitle({
        title: res.user_info.name,
      });
    });
  },
  viewTrip(e) {
    const ds = e.currentTarget.dataset;
    wx.navigateTo({
      url: `../tripdetail/tripdetail?id=${ds.id}&name=${ds.name}`,
    });
  },
});
